/*
* Copyright 2017 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-maintenanceorder
*
* @File name : MaintenanceorderConstant.java
*
* @Author : Administrator
*
* @Date : 2017年3月7日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2017年3月7日    Administrator    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/
	
package com.yonyou.gmmc.service.information.constant;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.yonyou.gmmc.service.information.util.MD5Encrypt;


/**
*
* @author Administrator
* 咨询活动公共常量定义
* @date 2017年3月7日
*/

public class InformationConstant {

    public static final String SERVICE_NAME = "information";
    public static final String VERSION = "v1";
    public static final String SERVICE_NAME_ZH = "咨询活动";
    public static final String BASE_PATH = "/" + SERVICE_NAME + "/api";

    public static final String BASE_PACKAGE="com.yonyou.gmmc.service.information";
    public static final String UTIL_PACKAGE=BASE_PACKAGE+".util";
    public static final String DAO_PACKAGE=BASE_PACKAGE+".dao";
    public static final String MODEL_PACKAGE=BASE_PACKAGE+".model";
    
    public static final int EFFECTIVE_READING_NUMBER = 5;
    public static final String HEADER_OPENID="gmmc.openid";

    public static final String publickey = "Gmmc_Members_Operation";

    public static final String visitor = "byOfficialWeChat";

    public static final String privatekey = "asldkjfhalkjdrmn34df";
    
    public static final String slyderAdventuresURL = genSlyderAdventuresURL();

    public static String genSlyderAdventuresURL() {

        String baseURL = "http://gmmc-wechat.bjscfl.com/index.php?g=Interface&m=GmmcMembers&a=integral";

        Map<String, Object> param = new HashMap<String, Object>();

        String timestamp = new Date().getTime() + "";

        param.put("privatekey", privatekey);
        param.put("visitor", visitor);
        param.put("publickey", publickey);
        param.put("timestamp", timestamp);

        param.put("token", MD5Encrypt.MD5Encode(publickey + "&" +  timestamp + "&" +  privatekey));

        return baseURL + "&" + getUrlParamsByMap(param);
    }
    
    public static String getUrlParamsByMap(Map<String, Object> map) {
        if (map == null) {
            return "";
        }
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            sb.append(entry.getKey() + "=" + entry.getValue());
            sb.append("&");
        }
        String s = sb.toString();
        if (s.endsWith("&")) {
            s = org.apache.commons.lang.StringUtils.substringBeforeLast(s, "&");
        }
        return "".equals(s) ? "errorGenerateURL=true" : s;
    }
}
